/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package webSiteDataStore;

import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Profile;

public class OthersData
{
    private static final Logger theLogger = Logger.getLogger(OthersData.class.getName());

    public static ArrayList<Profile> getProfiles(int currentUserId)
    {
        ArrayList<Profile>  profilesArray = null;
        Connection          connection = null;
        PreparedStatement   preparedStatement = null;
        ResultSet           resultSet = null;

        try
        {
            connection = ConnectionPool.getConnection();
            String sqlStatement = "SELECT * FROM UsersProfiles WHERE userid <> " + currentUserId;
            preparedStatement = connection.prepareStatement(sqlStatement);
            preparedStatement.executeQuery();
            resultSet = preparedStatement.getResultSet();
            profilesArray = new ArrayList<Profile>();
            while (resultSet.next())
            {
                int userId = resultSet.getInt("userid");
                String firstName = resultSet.getString("firstName");
                String lastName = resultSet.getString("lastName");
                String emailAddress = resultSet.getString("emailAddress");

                Profile profile = new Profile(userId, firstName, lastName, emailAddress);
                profilesArray.add(profile);
            }
        }
        catch(SQLException e)
        {
            theLogger.log(Level.SEVERE, null, e);
        }
        finally
        {
            SafeFreeResource.closeResultSet(resultSet);
            SafeFreeResource.closeStatement(preparedStatement);
            SafeFreeResource.closeConnection(connection);
            return profilesArray;
        }
    }
}
